package com.df.gamesynctest.net;

import com.df.gamesynctest.msg.*;

import java.util.HashMap;
import java.util.Map;

public class MsgManager {
    private static MsgManager  instance = new MsgManager();
    private MsgManager(){}

    public static MsgManager getInstance(){
        return instance;
    }
    public  Map<Integer,Class<?>> msgId2Type = new HashMap<>();
    public  Map<Class<?>,Integer> msgType2id = new HashMap<>();

    //注册消息
    public void registerMsg(){
        int id = C2S_EnterMap.class.getSimpleName().hashCode();
        msgId2Type.put(id,C2S_EnterMap.class);
        msgType2id.put(C2S_EnterMap.class,id);

        id = C2S_EnterMapSuccess.class.getSimpleName().hashCode();
        msgId2Type.put(id,C2S_EnterMapSuccess.class);
        msgType2id.put(C2S_EnterMapSuccess.class,id);

        id = S2C_SyncId.class.getSimpleName().hashCode();
        msgId2Type.put(id,S2C_SyncId.class);
        msgType2id.put(S2C_SyncId.class,id);

        id = S2C_SynAroundObjs.class.getSimpleName().hashCode();
        msgId2Type.put(id, S2C_SynAroundObjs.class);
        msgType2id.put(S2C_SynAroundObjs.class,id);

        id = S2C_MonsterMoveTo.class.getSimpleName().hashCode();
        msgId2Type.put(id,S2C_MonsterMoveTo.class);
        msgType2id.put(S2C_MonsterMoveTo.class,id);

        id = C2S_Move.class.getSimpleName().hashCode();
        msgId2Type.put(id,C2S_Move.class);
        msgType2id.put(C2S_Move.class,id);

        id = S2C_PlayerMove.class.getSimpleName().hashCode();
        msgId2Type.put(id,S2C_PlayerMove.class);
        msgType2id.put(S2C_PlayerMove.class,id);
    }

    //TODO 扫描指定包下的类,自动注册消息
}
